package com.swfee.qinben.adpt;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.swfee.qinben.R;
import com.swfee.qinben.util.CurenActivitUtils;

// 适配器
public class CommentReplyAdapter extends BaseAdapter {

	private JSONArray jSONArray;
	private Context context;
	private LayoutInflater inflater;

	public CommentReplyAdapter(JSONArray jSONArray, Context context) {
		this.jSONArray = jSONArray;
		this.context = context;
		this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		;
	}

	@Override
	public int getCount() {
		return jSONArray.length();
	}

	@Override
	public Object getItem(int position) {
		try {
			return jSONArray.get(position);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = inflater.inflate(R.layout.schedule_comment_reply_include, null);
			TextView replyComment = (TextView) convertView.findViewById(R.id.reply_comment);
			try {
				JSONObject model = jSONArray.getJSONObject(position);
				String replyCommentHTML ="<font color=\"red\">"+model.getString("replyUser")+":</font>"+model.getString("content");
				replyComment.setText(Html.fromHtml(replyCommentHTML));
				CurenActivitUtils.setTextViewContent(R.id.reply_time, model.getString("replyDate"), convertView);
			} catch (JSONException e) {
				e.printStackTrace();
			}
			
		}

		return convertView;
	}
}